package fr.syntheses.blog.Model.DAO;

import java.sql.Connection;
import java.sql.SQLException;
import javax.servlet.ServletContext;
import javax.sql.DataSource;
import org.apache.struts2.ServletActionContext;

import fr.syntheses.blog.Service.Log.LogSupport;
import fr.syntheses.blog.Service.Log.MyActionSupport;


// Classe de connexion
public class ModeleDAO extends LogSupport implements DAO
{	
	DataSource dataSource=null;
	
	// R�cup�rer une connexion
	public Connection getConnection() 
	{
		ServletContext servletContext=ServletActionContext.getServletContext();
		if(this.dataSource==null)
		{
			dataSource=(DataSource)servletContext.getAttribute("dataSource");
		}
		Connection connection=null;
		if(dataSource!=null)
		{
			try
			{
				connection=dataSource.getConnection();
			}
			catch(SQLException e)
			{
				System.out.println(e);
			}
		}
		
		// retourner la connexion
		return connection;
	}
	
	
	// Positionner une dataSource
	public void setConnection(DataSource dataSource)
	{
		this.dataSource=dataSource;
	}
}
